﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core;

namespace COFE.Core.Logger
{
    public interface IEventDispatcher<T>
        where T : EventArgs
    {
        IEventListener<T> SpawnListener(Action<object, T> onDispatch, bool register = true);

        void RegisterListener(IEventListener<T> listener);
        void UnregisterListener(IEventListener<T> listener);
        void DispatchEvent(object sender, T args);
    }

    public static class IEventDispatcherExtension
    {
        public static IEventListener<T> SpawnConsoleListener<T>(this IEventDispatcher<T> dispatcher) where T : EventArgs
        {
            return dispatcher.SpawnListener(
                (o, t) => 
                {                    
                    Console.WriteLine(String.Format("{0} - {1}", o.ToString(), t.ToString())); 
                }
            , true);
        }
    }

}
